package com.nice.nice201110.controller;


import com.nice.nice201110.service.TniceFileService;
import com.nice.nice201110.utils.NiceEnum;
import com.nice.nice201110.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/nicefile")
public class TniceFileController {

    @Autowired
    TniceFileService tniceFileService;

    private Map<String,Object> codeMes = new HashMap<String,Object>();
    /**
     * @param files 上传文件
     **/
    @RequestMapping(method = RequestMethod.POST,value = "/update")
    @ResponseBody
    public Map<String,Object> update(HttpServletRequest request,MultipartFile[] files) {
        HttpSession session = request.getSession();
        UserVo userVo = (UserVo)session.getAttribute("USER");
        if(userVo==null){
            codeMes.put("code", NiceEnum.code_300);
            codeMes.put("message",NiceEnum.NiceMap.get(NiceEnum.code_300));
            return codeMes;
        }
        List<String> listFile = tniceFileService.insert(userVo,files);
        if(listFile.size()>0){
            codeMes.put("code", NiceEnum.code_200);
            codeMes.put("message", NiceEnum.NiceMap.get(NiceEnum.code_200));
            codeMes.put("data", listFile);
            return codeMes;
        }
        codeMes.put("code",NiceEnum.code_100);
        codeMes.put("message",NiceEnum.NiceMap.get(NiceEnum.code_100));
        return codeMes;
    }
}
